#include <stdio.h>
#include <stdlib.h>
#include <chkd.h>
#include "astring/astring.h"

void astrcreate_test()
{
    astr str = astrcreate("Hello");
    chkd_str_eq(astrgetstring(&str), "Hello");
}

void astrfree_test()
{
    astr str = astrcreate("Hola");
    astrfree(&str);
    chkd_int_eq(astrlen(&str), 0);
    chkd_str_eq(astrgetstring(&str), NULL);
}

void astrlen_test()
{
    astr str = astrcreate("User");
    chkd_int_eq(astrlen(&str), 4);
}

void astrcat_test()
{
    astr str1 = astrcreate("Hello, ");
    astr str2 = astrcreate("World!");
    astrcat(&str1, &str2);
    chkd_str_eq(astrgetstring(&str1), "Hello, World!");
}

void astrcmp_test()
{
    astr str1 = astrcreate("hello");
    astr str2 = astrcreate("hello");
    printf("%d\n", astrcmp(&str1, &str2));
}
void astrncmp_test()
{
    astr str1 = astrcreate("hello");
    astr str2 = astrcreate("hello");
    printf("%d\n", astrncmp(&str1, &str2, str1.length));
}

void astrmult_test()
{
    astr str = astrcreate("*");
    astrmult(&str, 8);
    chkd_str_eq(astrgetstring(&str), "********");
    printf("%s\n", str.data);
    printf("%zu\n", str.length);
}

void astrcpy_test()
{
    astr str1;
    astr str2 = astrcreate("Hello, World!");
    astrcpy(&str1, &str2);
    chkd_str_eq(astrgetstring(&str1), "Hello, World!");
    printf("%s\n", str1.data);
    printf("%zu\n", str1.length);
}

void astrtoi_test()
{
    astr str = astrcreate("123");
    chkd_int_eq(astrtoi(&str), 123);
    printf("%d\n", astrtoi(&str));
}

main(void)
{
    astrtoi_test();
    return 0;
}
